package com.elai.web.controller.baseconfig;

import com.elai.common.annotation.Log;
import com.elai.common.core.controller.BaseController;
import com.elai.common.core.domain.AjaxResult;
import com.elai.common.core.page.TableDataInfo;
import com.elai.common.enums.BusinessType;
import com.elai.common.utils.poi.ExcelUtil;
import com.elai.baseconfig.domain.ChannelTemplateDO;
import com.elai.baseconfig.service.ChannelTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 模板配置Controller
 *
 * @author elai
 * @date 2021-04-03
 */
@RestController
@RequestMapping("/config/template")
public class ChannelTemplateController extends BaseController
{
    @Autowired
    private ChannelTemplateService channelTemplateService;

    /**
     * 查询模板配置列表
     */
    @PreAuthorize("@ss.hasPermi('config:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChannelTemplateDO channelTemplate)
    {
        startPage();
        List<ChannelTemplateDO> list = channelTemplateService.selectChannelTemplateList(channelTemplate);
        return getDataTable(list);
    }

    @GetMapping("/templateList")
    public AjaxResult templateList(ChannelTemplateDO channelTemplate)
    {
        List<ChannelTemplateDO> list = channelTemplateService.selectChannelTemplateList(channelTemplate);
        return AjaxResult.success(list);
    }


    /**
     * 导出模板配置列表
     */
    @PreAuthorize("@ss.hasPermi('config:template:export')")
    @Log(title = "模板配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ChannelTemplateDO channelTemplate)
    {
        List<ChannelTemplateDO> list = channelTemplateService.selectChannelTemplateList(channelTemplate);
        ExcelUtil<ChannelTemplateDO> util = new ExcelUtil<ChannelTemplateDO>(ChannelTemplateDO.class);
        return util.exportExcel(list, "template");
    }

    /**
     * 获取模板配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('config:template:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(channelTemplateService.selectChannelTemplateById(id));
    }

    /**
     * 新增模板配置
     */
    @PreAuthorize("@ss.hasPermi('config:template:add')")
    @Log(title = "模板配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChannelTemplateDO channelTemplate)
    {
        return toAjax(channelTemplateService.insertChannelTemplate(channelTemplate));
    }

    /**
     * 修改模板配置
     */
    @PreAuthorize("@ss.hasPermi('config:template:edit')")
    @Log(title = "模板配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChannelTemplateDO channelTemplate)
    {
        return toAjax(channelTemplateService.updateChannelTemplate(channelTemplate));
    }

    /**
     * 删除模板配置
     */
    @PreAuthorize("@ss.hasPermi('config:template:remove')")
    @Log(title = "模板配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(channelTemplateService.deleteChannelTemplateByIds(ids));
    }
}
